import os
from supabase import create_client, Client
from dotenv import load_dotenv

load_dotenv()
 
class SupabaseService:
    def __init__(self):
        url: str = os.environ.get("SUPABASE_URL")
        key: str = os.environ.get("SUPABASE_KEY")
        supabase: Client = create_client(url, key)
        self.client = supabase
    def client(self):
        return self.client
    def signUp(self, email: str, password: str):
        return self.client.auth.sign_up({'email':email, 'password':password})
    def signIn(self, email: str, password: str):
        return self.client.auth.sign_in_with_password({'email':email, 'password':password})
    def signOut(self):
        return self.client.auth.sign_out()
    def getUser(self):
        return self.client.auth.user()
        
if __name__ == '__main__':
    supabaseService = SupabaseService()
    # resp = supabaseService.signUp('xxxx@jishuba.cn', 'xxxx1234')
    resp = supabaseService.signIn('xxxx@jishuba.cn', 'xxxx1234')
    
    print(resp)
    # supabaseService.client.table('quiz') \
    #     .insert([{'basic_info': {}, 'content': []}]).execute()
    print('ok')